package com.dayu.web.controller;

import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dayu.finecomm.pojo.DeviceConfig;
import com.dayu.web.param.DeviceId;
import com.dayu.web.param.DscParam;
import com.dayu.web.service.DscService;
import com.dayu.web.utils.YamlUtil;
import com.dayu.web.vo.RESTResponse;

/**
 * 关于dsc配置
 * 
 * @author Chenjiawei
 *
 *         2017年11月9日
 */
@Controller
@RequestMapping("/unitalk/v1.0")
public class DscCtrl {

	static Logger LOGGER = LoggerFactory.getLogger(DscCtrl.class);

	@Resource
	DscService dscService;

	/**
	 * 获取dsc配置
	 * 
	 * @param token
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/dscs.json", method = RequestMethod.POST)
	public String getDscs(@RequestBody DeviceId param) {

		if (YamlUtil.isExist()) {

			List<String> list = dscService.getDsc(param.srcName);

			return RESTResponse.of(list).toString();
		} else {

			return RESTResponse.of(1, "获取dsc配置失败!").toString();
		}

	}

	/**
	 * 修改dsc配置
	 * 
	 * @param token
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/dsc/update.json", method = RequestMethod.POST)
	public String updateDsc(@RequestBody DscParam param) {

		if (YamlUtil.isExist()) {

			List<DeviceConfig> list = dscService.updateDsc(param.srcName,
					param.dsc);
			YamlUtil.setProper(list);

			return RESTResponse.of(0, "配置dsc成功！").toString();
		} else {

			return RESTResponse.of(1, "配置dsc成功！").toString();
		}

	}

}
